﻿package com.redStone.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.codec.digest.DigestUtils;

import com.redStone.exception.RedException;

public class Util {
	/**
	* @Title: 加密文本
	* @Description: 杩斿洖涓�涓狹D5鍔犲瘑鍚庨暱搴︿�?2涓瓧绗︾殑瀛楃涓�?
	* @param str
	* @return String
	* @author Administrator
	* @date 2018骞�5鏈�23鏃ヤ笅鍗�?:00:45
	 */
	public static String encryptText(String str) {
        return DigestUtils.md5Hex(str);
	}
	/**
	 * 
	* @Title: 加载配置文件
	* @Description: 绗竴娆″姞杞芥椂浠�?db.properties 璇诲彇鏁版嵁搴撻厤缃俊鎭�
	* @param filepath
	* @return
	* @throws IOException Properties
	* @author Administrator
	* @date 2018骞�5鏈�23鏃ヤ笅鍗�?:32:57
	 */
	public static Properties loadFile(String filepath) throws IOException {
		// 璇诲叆閰嶇疆鏂囦�?
		InputStream in=DBUtil.class.getClassLoader().getResourceAsStream(filepath);
		// 鍒涘缓閰嶇疆鏂囦欢瀵硅�?
		Properties prop=new Properties();
		// 璇诲叆鏂囦欢娴�
		prop.load(in);
		return prop;
	}
	/**
	 * 设置编码
	* @Title: setEncode 
	* @Description: TODO 
	* @param request
	* @param response
	* @param filepath
	* @throws IOException void
	* @author zuxia
	 * @throws RedException 
	 * @throws UnsupportedEncodingException 
	* @date 2018骞�5鏈�28鏃ヤ笂鍗�?:05:25
	 */
	public static void setEncode(HttpServletRequest request,HttpServletResponse response) {
		try {
			request.setCharacterEncoding("UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		response.setContentType("text/html;charset=UTF-8");
	}
}
